package member.model;

import java.sql.SQLException;
import java.util.ArrayList;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

import to.MemberTO;

public class MemberDAO {
	private SqlMapClientTemplate sqlMap;
	public MemberDAO(SqlMapClientTemplate sqlMap){
		this.sqlMap = sqlMap;
	}
	
	public MemberTO selectMemberById(String memberId) throws SQLException{
		return (MemberTO)sqlMap.queryForObject("selectMemberById", memberId);
	}
	
	public MemberTO selectMemberByPhone(String phone) throws SQLException{
		return (MemberTO) sqlMap.queryForList("selectMemberByPhone", phone);
	}
	
	public MemberTO selectMember(String MemberId) throws SQLException{
		return (MemberTO) sqlMap.queryForObject("selectMember", MemberId);
	}
	
	//회원 정보를 DB에 insert하는 메소드
	//회원가입
	public void insertMember(MemberTO mto) throws SQLException{
		sqlMap.insert("insertMember", mto);
	}
	
	//회원정보 삭제(탈퇴)
	public void deleteMemberById(String MemberId) throws SQLException{
		sqlMap.delete("deleteMemberById", MemberId);
	}
	
	//전체 회원정보 조회
	@SuppressWarnings("unchecked")
	public ArrayList<MemberTO> selectAllMember() throws SQLException{
		return (ArrayList<MemberTO>) sqlMap.queryForList("selectAllMember");
	}
	
	//회원정보 수정
	public void updateMember(MemberTO mto) throws SQLException{
		sqlMap.update("updateMember", mto);
	}
	
	//이름으로 조회
	@SuppressWarnings("unchecked")
	public ArrayList<MemberTO> selectMemberByName(String name) throws SQLException{
		return (ArrayList<MemberTO>)sqlMap.queryForList("selectMemberByName", name);
	}
}

